using Game;
using RoslynCSharp;
using SMGCore;
using UnityEngine;
using Voxels;

public sealed class CommonStaticData : ManualSingleton<CommonStaticData> {
	public LayerMask AllCollisionsMask;
	public LayerMask DynamicEntitiesMask;
	public LayerMask StaticEntitiesMask;

	public AssemblyReferenceAsset[] DefaultScriptAssemlies;
	public TextAsset                DefaultProgramText;

	public static TeamType GetRandomTeam() {
		return Random.value < 0.5f ? TeamType.Red : TeamType.Blue;
	}

	public static bool CanDealDamage(TeamType attacker, TeamType victim) {
		switch (attacker ) {
			case TeamType.Neutral:
				return victim == TeamType.Neutral || victim == TeamType.Red || victim == TeamType.Blue || victim == TeamType.Rogue;
			case TeamType.Red:
				return victim == TeamType.Neutral || victim == TeamType.Blue || victim == TeamType.Rogue;
			case TeamType.Blue:
				return victim == TeamType.Neutral || victim == TeamType.Red || victim == TeamType.Rogue;
			case TeamType.Rogue:
				return victim == TeamType.Neutral || victim == TeamType.Red || victim == TeamType.Blue || victim == TeamType.Rogue;
			case TeamType.Holy:
				return true;
			default:
				return false;
		}
	}

	public static bool IsHostileTeam(TeamType first, TeamType second) {
		switch ( first ) {
			case TeamType.Neutral:
				return second == TeamType.Rogue;
			case TeamType.Red:
				return second == TeamType.Blue|| second == TeamType.Rogue;
			case TeamType.Blue:
				return second == TeamType.Red || second == TeamType.Rogue;
			case TeamType.Rogue:
				return second != TeamType.Holy;
			case TeamType.Holy:
				return false;
			default:
				return false;
		}
	}

	public static bool IsInventoryItemStackable(BaseInventoryItem item) {
		return GetInventoryStackSize(item) > 1;
	}

	public static int GetInventoryStackSize(BaseInventoryItem item) {
		if ( item == null ) {
			return 0;
		}
		if ( item.ItemType == InventoryItemType.Block ) {
			return 50;
		}
		if ( item.ItemType == InventoryItemType.Debris ) {
			return 50;
		}
		if ( item.ItemType == InventoryItemType.Ammo ) {
			return 10;
		}

		if ( item.ItemType == InventoryItemType.Artifact ) {
			return 1;
		}
		return 1;
	}

	public static int GetItemPrice(BaseInventoryItem item) {
		if ( item == null ) {
			return 0;
		}
		if ( item.ItemType == InventoryItemType.Block ) {
			var blockinfo = ((BlockItem)item)?.BlockData.Info;
			return blockinfo.Price;
		}
		if ( item.ItemType == InventoryItemType.Debris) {
			return 20;
		}
		if ( item.ItemType == InventoryItemType.Ammo) {
			return 15;
		}

		if ( item.ItemType == InventoryItemType.Artifact) {
			return 5000;
		}
		return 1;
	}


}
